package org.scorpios.search.analyzer;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.PathUtils;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider;

import java.io.File;
import java.nio.file.Path;

/**
 * @author zhangxudong
 * @date 2022/11/12 20:20
 * @desc
 */
public class SearchAnalyzerProvider extends AbstractIndexAnalyzerProvider<SearchAnalyzer> {
    private final static Logger LOG = LogManager.getLogger(SearchAnalyzerProvider.class);
    private final SearchAnalyzer searchAnalyzer;

    public SearchAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
        super(indexSettings, name, settings);
        searchAnalyzer = new SearchAnalyzer();
        //设置jieba分词的配置路径信息
        Path configPath = PathUtils.get(new File(SearchAnalyzer.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent()).toAbsolutePath().resolve("jieba_config.properties");
        LOG.info("开始加载配置文件:[{}]", configPath.toAbsolutePath());
    }

    @Override
    public SearchAnalyzer get() {
        return searchAnalyzer;
    }
}
